package com.tang.thepath.adapter;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.king.photo.util.Bimp;
import com.luck.picture.lib.entity.LocalMedia;
import com.tang.thepath.R;

import java.util.ArrayList;
import java.util.List;

public class GridAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private int selectedPosition = -1;
    private boolean shape;
    private Context context;

    public List<Bitmap> getDataList() {
        return dataList;
    }

    public void setDataList(List<Bitmap> dataList) {
        this.dataList = dataList;
    }

    private List<Bitmap> dataList = new ArrayList<>();

    public boolean isShape() {
        return shape;
    }

    public void setShape(boolean shape) {
        this.shape = shape;
    }

    public GridAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }


    public int getCount() {
//        if(Bimp.tempSelectBitmap.size() == 9){
//            return 9;
//        }
//        return (Bimp.tempSelectBitmap.size() + 1);
        return this.dataList.size() + 1;
    }

    public Object getItem(int position) {
        return this.dataList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }

    public int getSelectedPosition() {
        return selectedPosition;
    }




    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_published_grida,
                    parent, false);
            holder = new ViewHolder();
            holder.image = (ImageView) convertView
                    .findViewById(R.id.item_grida_image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (position == this.dataList.size()) {
            holder.image.setImageBitmap(BitmapFactory.decodeResource(
                    context.getResources(), R.drawable.icon_addpic_unfocused));
            if (position == 9) {
                holder.image.setVisibility(View.GONE);
            }
        } else {
            holder.image.setImageBitmap(this.dataList.get(position));
        }

        return convertView;
    }

    public class ViewHolder {
        public ImageView image;
    }



}
